Skip to content

Conversation

grdsdev
Copy link
Contributor

@grdsdev grdsdev commented Sep 25, 2025

Summary

  • Add enabled field to RealtimeChannelPresenceConfig type definition
  • Add _has_callback_attached property to AsyncRealtimePresence class to detect if any presence callbacks are registered
  • Modify channel subscription logic to automatically set presence.enabled=true when presence callbacks are attached or manually configured
  • Add automatic resubscription functionality when presence callbacks are added to an already joined channel

Test plan

  • Add unit tests for _has_callback_attached property
  • Add tests for presence config type validation with enabled field
  • Add integration tests for automatic presence.enabled flag setting
  • Add tests for automatic resubscription behavior when callbacks are added post-join
  • Verify all existing presence functionality continues to work as expected

🤖 Generated with Claude Code

grdsdev and others added 3 commits September 25, 2025 17:15
- Add enabled field to RealtimeChannelPresenceConfig type
- Add _has_callback_attached property to AsyncRealtimePresence
- Set presence.enabled based on callback attachment or manual config
- Add automatic resubscription when presence callbacks are added to joined channel
- Add comprehensive tests for new functionality

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Fix AttributeError by mocking _ws_connection instead of trying to set is_connected property
- Ensure test properly mocks socket connection for presence enabled flag validation

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@grdsdev grdsdev requested a review from o-santi September 25, 2025 20:23
logger.info(
f"channel {self.topic} resubscribe due to change in presence callbacks on joined channel"
)
asyncio.create_task(self._resubscribe())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@o-santi not sure if this create_task is appropriate here, should I hold a reference for the task to make sure it is finished/cancelled?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, we can hold a reference but there's no real way to make sure its finished without randomly throwing errors, as we cannot raise something out of thin air.

If we really want to make sure it's finished, we should spawn a local loop and run it in there ... which is finicky. By the nature of unsubscribe and subscribe, we are not sure that we've got any state change, as the only thing those two functions do is send the message.

In order to properly handle this, these functions should've been async in the first place, but that can only be changed in the V3.

@grdsdev grdsdev merged commit 6be6c0c into main Sep 29, 2025
19 of 34 checks passed
@grdsdev grdsdev deleted the guilherme/clibs-218-realtime-py-add-presence-enabled-flag-on-join-payload branch September 29, 2025 08:39
grdsdev added a commit to supabase/supabase that referenced this pull request Sep 30, 2025
Update documentation to reflect the automatic presence enablement behavior
introduced in supabase-py PR #1229. Presence is now automatically enabled
when presence callbacks are attached to a channel.

Changes:
- Updated subscribe() method notes in supabase_py_v2.yml
- Added note about automatic presence enablement when callbacks are attached
- Documented automatic resubscription behavior when callbacks are added post-join
- Maintains existing documentation structure and formatting

Source: supabase/supabase-py#1229

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants